<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>添加用户</title>
    <!--    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.6.9/css/layui.min.css"/>-->
    <!--    <script src="https://cdn.staticfile.org/layui/2.6.9/layui.min.js"></script>-->
    <link rel="stylesheet" href="lib/layui/css/layui.css">
    <script type="text/javascript" src="lib/layui/layui.js"></script>
    <script type="text/javascript" src="js/jquery.min.js"></script>
</head>

<body>
<div class="login-container">
    <form class="layui-form" id="user">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="username" required lay-verify="required" lay-reqtext="请输入用户名"
                       placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" lay-reqtext="请输入密码"
                       placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
                <select name="sex" lay-verify="sex" id="sex">
                    <option value="1">请选择性别</option>
                    <option value="男">男</option>
                    <option value="女">女</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出生日期</label>
            <div class="layui-input-inline">
                <input type="text" name="time" id="date" required lay-verify="required|date" lay-reqtext="请输入日期"
                       placeholder="请输入日期" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份证</label>
            <div class="layui-input-inline">
                <input type="text" name="identityCard" required lay-verify="required|identity"
                       lay-reqtext="请输入身份证"
                       placeholder="请输入身份证" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" required lay-verify="required|phone" lay-reqtext="请输入电话"
                       placeholder="请输入电话" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所在单位</label>
            <div class="layui-input-inline">
                <input type="text" name="unit" lay-reqtext="请输入所在单位"
                       placeholder="请输入所在单位" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-inline">
                <input type="text" name="address" lay-reqtext="请输入地址"
                       placeholder="请输入地址" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-inline">
                <select name="jobType" lay-verify="jobType" id="jobType">
                    <option value="0">请选择角色</option>
                    <option value="1">军事迷</option>
                    <option value="2">评论员</option>
                    <option value="3">指挥员</option>
                    <option value="4">情报收集者</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" lay-reqtext="请输入邮箱"
                       placeholder="请输入邮箱" lay-verify="email" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" name="remarks" lay-reqtext="请输入备注"
                       placeholder="请输入备注" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="addButton" lay-submit lay-filter="add" type="submit">添加</button>
                <button type="reset" class="layui-btn">重置</button>
            </div>
        </div>
    </form>
</div>

<script>

</script>
<style>
    .login-container {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
    }
</style>
<script th:inline="javascript" type="text/javascript" rel="script">
    layui.use(['table', 'laydate','form'], function () {
        let form = layui.form;
        let layer = layui.layer;
        let layDate = layui.laydate;

        layDate.render({
            elem: '#date'
        });


        form.on('submit(add)', function (data) {
            let user = $("#user").serialize();
            $.post('/user/addUser', user, (result) => {
                if (result.state == 200) {
                    layer.msg(result.message, {
                        icon: 1,
                        time: 3000
                    });
                    table.reload('userInfo');

                } else {
                    layer.msg(result.message, {
                        icon: 2,
                        time: 3000
                    });
                    table.reload('userInfo');
                }
            });
            return false;
        });

        layui.form.verify({
            sex: function (value, item) {
                if (value == 1) {
                    return '请选择性别';
                }
            },
            jobType: function (value, item) {
                if (value == 0) {
                    return '请选择权限';
                }
            }
        });

    });
</script>
</body>

</html>
